// https://www.masswerk.at/6502/assembler.html

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>

import cpu6502;

nes8::CPU6502 l;
nes8::memory m;

TEST_CASE("Example test")
{
    l.reg.a = 0x00;
    l.reg.pc = 0x0000;
    l.reg.sp = 0xff;
    l.reg.x = 0x00;
    l.reg.y = 0x00;
    l.reg.p = 0b00110000;
    SUBCASE("LDA Immediate")
    {
        m[0x0000] = 0xA9;
        m[0x0001] = 0x10;

        execute_instruction<nes8::LDA, nes8::Immediate>(l.reg, m);
        CHECK_EQ(l.reg.a, 0x10);
        CHECK_EQ(l.reg.pc, 0x0002);

        CHECK_EQ(l.reg.p, 0b00110000);
    }
    SUBCASE("LDA IndirectX")
    {
        l.reg.x = 0x05;
        m[0x0000] = 0xA1;
        m[0x0001] = 0x70;
        m[0x0075] = 0x23;
        m[0x0076] = 0x30;
        m[0x3023] = 0xA5;

        execute_instruction<nes8::LDA, nes8::IndirectX>(l.reg, m);
        CHECK_EQ(l.reg.a, 0xA5);
        CHECK_EQ(l.reg.pc, 0x0002);

        CHECK_EQ(l.reg.p, 0b10110000);
    }
}